package com.googlecode.curvedmetromaps.core.model;

import java.util.Collection;

public class MetroLine {
	public MetroStation[]	stations;

	/**
	 * Unique line ID in the context of a metro map. The id is in the range
	 * 0..l-1, where l is the number of lines.
	 */
	public int				id;

	/** True if this line is a cycle; false otherwise. */
	public boolean			isCycle;

	/** Friendly name of the line. */
	public String			label;

	/** Optional external reference. */
	public String			ref;

	/** Bytes in order of significance determine opacity, red, green, blue. */
	public int				color;

	public MetroLine() {
	}

	public MetroLine(Collection<MetroStation> stations) {
		this.stations = new MetroStation[stations.size()];
		this.stations = stations.toArray(this.stations);
		if (stations.size() > 0) {
			// HACK: quick cycle detection
			isCycle = (this.stations[0] == this.stations[stations.size() - 1]);
		}
	}

/**
 * Copy constructor
 * @param metroLine MetroLine to copy from, but don't use station references.
 * @param stations Array with MetroStation objects to reference.
 */
	public MetroLine(MetroLine metroLine, MetroStation[] stations) {
		this.id = metroLine.id;
		this.isCycle = metroLine.isCycle;

		// Copy metro station references
		this.stations = new MetroStation[metroLine.stations.length];
		for (int i = 0; i < metroLine.stations.length; i++) {
			int id = metroLine.stations[i].id;
			this.stations[i] = stations[id];
		}
	}
}
